#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

class Solution {
public:

    vector<int> findOrder(int n, vector<vector<int> >& groups) {
        vector<vector<int>> edges(n);
        vector<int> in(n);

        for (auto e : groups) {
            int a = e[0], b = e[1];
            edges[b].push_back(a);
            in[a]++;
        }

        queue<int> q;

        for (int i = 0; i < n; i++) {
            if (in[i] == 0) {
                q.push(i);
            }
        }

        vector<int> v;

        while (q.size()) {
            int a = q.front();
            q.pop();
            v.push_back(a);
            for (auto b : edges[a]) {
                if (--in[b] == 0) {
                    q.push(b);
                }
            }
        }

        if (v.size() == n) {
            return v;
        }
        else return {};

        return v;
    }
};

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str;
    cin >> str;
    int _min = INT_MAX;
    for (int i = 'a'; i <= 'z'; i++)
    {
        int sum = 0;
        for (auto c : str)
        {
            sum += min(abs(c - i), 26 - abs(c - i));
        }
        _min = min(sum, _min);
    }
    cout << _min << endl;
    return 0;
}